//
//  WebViewOfCommendHead.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/1.
//  Copyright © 2016年 KX. All rights reserved.
//

#import "WebViewOfCommendHead.h"
#import "FreeTravelNetwork.h"
@interface WebViewOfCommendHead ()<UIWebViewDelegate>
@property (nonatomic, assign) BOOL isCollected;
@property (nonatomic, strong) UIWebView *webView;
@end

@implementation WebViewOfCommendHead
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('drains-app mGuideToAppBox')[0].style.display = 'none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('xd-list fix')[0].style.display = 'none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('xdetail-header')[0].style.display = 'none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('head-userinfo fix')[0].style.display = 'none'"];
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('bssDetTit jscmd')[0].style.display = 'none'"];
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('prb js_show_reply active')[0].style.display = 'none'"];
    
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('clearfix')[0].style.display = 'none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('qui-footerBasic')[0].style.display = 'none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('qui-header')[0].style.display = 'none'"];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
    self.webView.delegate = self;
    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:self.url]];
    [self.webView loadRequest:request];
    [self.view addSubview:_webView];
    
    
    
    
    //先收藏请求,判断是否收藏
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"sdfasadfas"] style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
   
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"xin"] style:UIBarButtonItemStylePlain target:self action:@selector(goCollection:)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
}

- (void)goCollection:(UIBarButtonItem *)barbuttonitem{
           if (self.isCollected == NO) {
            
            [FreeTravelNetwork POST:@"http://open.qyer.com/qyer/bbs/thread_update" andBody:[NSString stringWithFormat:@"client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&oauth_token=%@&oper=fav&page=1&tid=%ld&track_app_channel=App%%2520Store&track_app_version=7.0.1&track_device_info=iPhone%%25205s&track_deviceid=E9CA001A-5603-4CA8-B2EA-2BE34F691AC6&track_os=ios%%25209.3.5&track_user_id=%@&v=1",[[NSUserDefaults standardUserDefaults] stringForKey:@"access_token"],self.tid,[[NSUserDefaults standardUserDefaults] stringForKey:@"user_id"]] andBodyStyle:ZWYBodyString andHeader:@{@"Content-Type": @"application/x-www-form-urlencoded",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         @"Cookie": @"__utma=253397513.2045201602.1472089545.1474267378.1474277905.53; __utmb=253397513.4.9.1474277938274; __utmc=253397513; __utmt=1; __utmz=253397513.1472089545.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _guid=84639271-4ee1-e7cc-4fa4-85f96ce0f519; _session=1474277033849; als=0; cdb_auth=0948%2FzfUQoEZEZo392qtNBuTVJoroMsL07UfbRI8G8mjIIf%2FKsGNay6rqG1oQr6imTBLbycqAwUGSlfXJoLIJzrMs81JeA; new_uv=18; plan_token=4519bcc20a3265efa62e670f14b618b8; vh_ids_n=%5B%22448963_9%22%5D; yqf_cps=source%3Demar%26channel%3Dcps%26cid%3D18526%26wi%3DNTEzNzAzfDAwMTBiNDU1NDU5OTYxODY0OTAz",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         @"Content-Length": @"324",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         @"Connection": @"keep-alive",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         @"Proxy-Connection": @"keep-alive",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         @"Accept": @"*/*",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         @"User-Agent": @"QYER/7.0.1 (iPhone; iOS 9.3.5; Scale/2.00) Paros/3.2.13",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         @"Accept-Language": @"zh-Hans-CN;q=1, nl-CN;q=0.9, en-CN;q=0.8",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         @"X-Tingyun-Id": @"TFF1KOA8DJk;c=2;r=1035347492"} andResponse:ZWYJSON andSuccessBlock:^(id result) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             NSLog(@"%@",result);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         } andFailureBlock:^(NSError *error) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         }];
            self.navigationItem.rightBarButtonItem.image = [UIImage imageNamed:@"xin2"];
            self.isCollected = YES;
        }else{
            [FreeTravelNetwork POST:@"http://open.qyer.com/qyer/bbs/thread_update" andBody:[NSString stringWithFormat:@"client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&oauth_token=%@&oper=unfav&page=1&tid=%ld&track_app_channel=App%%2520Store&track_app_version=7.0.1&track_device_info=iPhone%%25205s&track_deviceid=E9CA001A-5603-4CA8-B2EA-2BE34F691AC6&track_os=ios%%25209.3.5&track_user_id=%@&v=1",[[NSUserDefaults standardUserDefaults] stringForKey:@"access_token"],self.tid,[[NSUserDefaults standardUserDefaults] stringForKey:@"user_id"]] andBodyStyle:ZWYBodyString andHeader:@{@"Content-Type": @"application/x-www-form-urlencoded",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           @"Cookie": @"__utma=253397513.2045201602.1472089545.1474267378.1474277905.53; __utmb=253397513.4.9.1474277938274; __utmc=253397513; __utmt=1; __utmz=253397513.1472089545.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _guid=84639271-4ee1-e7cc-4fa4-85f96ce0f519; _session=1474277033849; als=0; cdb_auth=0948%2FzfUQoEZEZo392qtNBuTVJoroMsL07UfbRI8G8mjIIf%2FKsGNay6rqG1oQr6imTBLbycqAwUGSlfXJoLIJzrMs81JeA; new_uv=18; plan_token=4519bcc20a3265efa62e670f14b618b8; vh_ids_n=%5B%22448963_9%22%5D; yqf_cps=source%3Demar%26channel%3Dcps%26cid%3D18526%26wi%3DNTEzNzAzfDAwMTBiNDU1NDU5OTYxODY0OTAz",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           @"Content-Length": @"326",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           @"Connection": @"keep-alive",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           @"Proxy-Connection": @"keep-alive",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           @"Accept": @"*/*",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           @"User-Agent": @"QYER/7.0.1 (iPhone; iOS 9.3.5; Scale/2.00) Paros/3.2.13",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           @"Accept-Language": @"zh-Hans-CN;q=1, nl-CN;q=0.9, en-CN;q=0.8",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           @"X-Tingyun-Id": @"TFF1KOA8DJk;c=2;r=1176210250"} andResponse:ZWYJSON andSuccessBlock:^(id result) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               NSLog(@"%@",result);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           } andFailureBlock:^(NSError *error) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           }];
            self.navigationItem.rightBarButtonItem.image = [UIImage imageNamed:@"xin"];
            self.isCollected = NO;
        }
    
    
    
    
    

}
- (void)handleGo{
    [FreeTravelNetwork POST:@"http://open.qyer.com/qyer/bbs/thread_update" andBody:[NSString stringWithFormat:@"client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&oauth_token=%@&oper=fav&page=1&tid=%ld&track_app_channel=App%%2520Store&track_app_version=7.0.1&track_device_info=iPhone%%25205s&track_deviceid=E9CA001A-5603-4CA8-B2EA-2BE34F691AC6&track_os=ios%%25209.3.5&track_user_id=%@&v=1",[[NSUserDefaults standardUserDefaults] stringForKey:@"access_token"],self.tid,[[NSUserDefaults standardUserDefaults] stringForKey:@"user_id"]] andBodyStyle:ZWYBodyString andHeader:@{@"Content-Type": @"application/x-www-form-urlencoded",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @"Cookie": @"__utma=253397513.2045201602.1472089545.1474267378.1474277905.53; __utmb=253397513.4.9.1474277938274; __utmc=253397513; __utmt=1; __utmz=253397513.1472089545.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _guid=84639271-4ee1-e7cc-4fa4-85f96ce0f519; _session=1474277033849; als=0; cdb_auth=0948%2FzfUQoEZEZo392qtNBuTVJoroMsL07UfbRI8G8mjIIf%2FKsGNay6rqG1oQr6imTBLbycqAwUGSlfXJoLIJzrMs81JeA; new_uv=18; plan_token=4519bcc20a3265efa62e670f14b618b8; vh_ids_n=%5B%22448963_9%22%5D; yqf_cps=source%3Demar%26channel%3Dcps%26cid%3D18526%26wi%3DNTEzNzAzfDAwMTBiNDU1NDU5OTYxODY0OTAz",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @"Content-Length": @"324",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @"Connection": @"keep-alive",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @"Proxy-Connection": @"keep-alive",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @"Accept": @"*/*",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @"User-Agent": @"QYER/7.0.1 (iPhone; iOS 9.3.5; Scale/2.00) Paros/3.2.13",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @"Accept-Language": @"zh-Hans-CN;q=1, nl-CN;q=0.9, en-CN;q=0.8",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @"X-Tingyun-Id": @"TFF1KOA8DJk;c=2;r=1035347492"} andResponse:ZWYJSON andSuccessBlock:^(id result) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            NSLog(@"%@",result);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        } andFailureBlock:^(NSError *error) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        }];
}
- (void)handleBack{
    [FreeTravelNetwork POST:@"http://open.qyer.com/qyer/bbs/thread_update" andBody:[NSString stringWithFormat:@"client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&oauth_token=%@&oper=unfav&page=1&tid=%ld&track_app_channel=App%%2520Store&track_app_version=7.0.1&track_device_info=iPhone%%25205s&track_deviceid=E9CA001A-5603-4CA8-B2EA-2BE34F691AC6&track_os=ios%%25209.3.5&track_user_id=%@&v=1",[[NSUserDefaults standardUserDefaults] stringForKey:@"access_token"],self.tid,[[NSUserDefaults standardUserDefaults] stringForKey:@"user_id"]] andBodyStyle:ZWYBodyString andHeader:@{@"Content-Type": @"application/x-www-form-urlencoded",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @"Cookie": @"__utma=253397513.2045201602.1472089545.1474267378.1474277905.53; __utmb=253397513.4.9.1474277938274; __utmc=253397513; __utmt=1; __utmz=253397513.1472089545.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _guid=84639271-4ee1-e7cc-4fa4-85f96ce0f519; _session=1474277033849; als=0; cdb_auth=0948%2FzfUQoEZEZo392qtNBuTVJoroMsL07UfbRI8G8mjIIf%2FKsGNay6rqG1oQr6imTBLbycqAwUGSlfXJoLIJzrMs81JeA; new_uv=18; plan_token=4519bcc20a3265efa62e670f14b618b8; vh_ids_n=%5B%22448963_9%22%5D; yqf_cps=source%3Demar%26channel%3Dcps%26cid%3D18526%26wi%3DNTEzNzAzfDAwMTBiNDU1NDU5OTYxODY0OTAz",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @"Content-Length": @"326",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @"Connection": @"keep-alive",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @"Proxy-Connection": @"keep-alive",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @"Accept": @"*/*",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @"User-Agent": @"QYER/7.0.1 (iPhone; iOS 9.3.5; Scale/2.00) Paros/3.2.13",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @"Accept-Language": @"zh-Hans-CN;q=1, nl-CN;q=0.9, en-CN;q=0.8",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @"X-Tingyun-Id": @"TFF1KOA8DJk;c=2;r=1176210250"} andResponse:ZWYJSON andSuccessBlock:^(id result) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              NSLog(@"%@",result);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          } andFailureBlock:^(NSError *error) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          }];
    self.navigationItem.rightBarButtonItem.image = [UIImage imageNamed:@"xin"];
}
- (void)goBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
